/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.fb.FreeBusyQuery;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetFreeBusy
/*     */   extends MailDocumentHandler
/*     */ {
/*     */   private static final long MSEC_PER_DAY = 86400000L;
/*     */   private static final long MAX_PERIOD_SIZE_IN_DAYS = 200L;
/*     */   
/*     */   protected static void validateRange(long rangeStart, long rangeEnd)
/*     */     throws ServiceException
/*     */   {
/*  56 */     if (rangeEnd <= rangeStart)
/*  57 */       throw ServiceException.INVALID_REQUEST("End time must be after Start time", null);
/*  58 */     long days = (rangeEnd - rangeStart) / 86400000L;
/*  59 */     if (days > 200L) {
/*  60 */       throw ServiceException.INVALID_REQUEST("Requested range is too large (Maximum 200 days)", null);
/*     */     }
/*     */   }
/*     */   
/*     */   public boolean needsAuth(Map<String, Object> context) {
/*  65 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean handlesAccountHarvesting()
/*     */   {
/*  75 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  80 */     ZimbraSoapContext zc = getZimbraSoapContext(context);
/*     */     
/*  82 */     long rangeStart = request.getAttributeLong("s");
/*  83 */     long rangeEnd = request.getAttributeLong("e");
/*  84 */     validateRange(rangeStart, rangeEnd);
/*     */     
/*  86 */     Element response = getResponseElement(zc);
/*     */     
/*     */ 
/*  89 */     String uidParam = request.getAttribute("uid", null);
/*  90 */     String idParam = request.getAttribute("id", null);
/*  91 */     String nameParam = request.getAttribute("name", null);
/*  92 */     String exApptUid = request.getAttribute("excludeUid", null);
/*     */     
/*  94 */     Account requestor = Provisioning.getInstance().get(Key.AccountBy.id, zc.getAuthtokenAccountId());
/*  95 */     FreeBusyQuery fbQuery = new FreeBusyQuery((HttpServletRequest)context.get("servlet.request"), zc, requestor, rangeStart, rangeEnd, exApptUid);
/*     */     
/*  97 */     String[] idStrs = null;
/*     */     
/*     */ 
/* 100 */     if (uidParam != null) {
/* 101 */       idStrs = uidParam.split(",");
/* 102 */       for (String idStr : idStrs)
/* 103 */         fbQuery.addId(idStr, -1);
/*     */     }
/* 105 */     if (idParam != null) {
/* 106 */       idStrs = idParam.split(",");
/* 107 */       for (String idStr : idStrs)
/* 108 */         fbQuery.addAccountId(idStr, -1);
/*     */     }
/* 110 */     if (nameParam != null) {
/* 111 */       idStrs = nameParam.split(",");
/* 112 */       for (String idStr : idStrs) {
/* 113 */         fbQuery.addEmailAddress(idStr, -1);
/*     */       }
/*     */     }
/* 116 */     for (Iterator<Element> usrIter = request.elementIterator("usr"); usrIter.hasNext();) {
/* 117 */       Element usrElem = (Element)usrIter.next();
/* 118 */       int folderId = (int)usrElem.getAttributeLong("l", -1L);
/* 119 */       if ((folderId == 1) || (folderId == 0))
/* 120 */         folderId = -1;
/* 121 */       String id = usrElem.getAttribute("id", null);
/* 122 */       if (id != null)
/* 123 */         fbQuery.addAccountId(id, folderId);
/* 124 */       String name = usrElem.getAttribute("name", null);
/* 125 */       if (name != null) {
/* 126 */         fbQuery.addEmailAddress(name, folderId);
/*     */       }
/*     */     }
/* 129 */     fbQuery.getResults(response);
/* 130 */     return response;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/GetFreeBusy.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */